#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
    int searchInsert(vector<int>& nums, int target)
    {
        if (target <= nums[0]) return 0;
        int left = 0, right = nums.size() - 1;
        while (left < right)
        {
            int mid = (right - left + 1) / 2 + left;
            if (nums[mid] == target)
                return mid;
            else if (nums[mid] < target)
                left = mid;
            else
                right = mid - 1;
        }
        return left + 1;
    }
};